import { BasicColumn, FormSchema } from '/@/components/Table';
import { h } from 'vue';
import { Image } from 'ant-design-vue';

export const columns: BasicColumn[] = [
  {
    key: 'fileName',
    title: '名称',
    dataIndex: 'fileName',
    width: 200,
  },
  {
    key: 'title',
    title: '标题',
    dataIndex: 'title',
  },
  {
    key: 'author',
    title: '作者',
    dataIndex: 'author',
  },
  {
    key: 'type',
    title: '图书类型',
    dataIndex: 'type',
  },
  {
    key: 'cover',
    title: '背景图',
    dataIndex: 'cover',
    customRender: ({ text }) => {
      return h(Image, { src: text, style: { width: '50px', height: '50px' } });
    },
  },
  {
    title: '操作',
    key: 'action',
    dataIndex: 'action',
  },
];

// 表单字段
export const searchFormSchema: FormSchema[] = [
  {
    field: 'name',
    label: '菜单名称',
    component: 'Input',
    colProps: { span: 8 },
  },
  {
    field: 'active',
    label: '状态',
    component: 'Select',
    componentProps: {
      options: [
        { label: '启用', value: '1' },
        { label: '停用', value: '0' },
      ],
    },
    colProps: { span: 8 },
  },
];

export const formSchema: FormSchema[] = [
  {
    field: 'name',
    label: '菜单名称',
    component: 'Input',
    required: true,
  },
  {
    field: 'path',
    label: '菜单地址',
    component: 'Input',
    required: true,
  },
  {
    field: 'redirect',
    label: '重定向',
    component: 'Input',
    required: false,
  },
  {
    field: 'meta',
    label: '元数据',
    component: 'Input',
    required: false,
  },

  {
    field: 'parentMenu',
    label: '上级菜单',
    component: 'TreeSelect',
    componentProps: {
      fieldNames: {
        label: 'name',
        key: 'id',
        value: 'id',
      },
      getPopupContainer: () => document.body,
    },
  },
  {
    field: 'active',
    label: '状态',
    component: 'RadioButtonGroup',
    defaultValue: '1',
    componentProps: {
      options: [
        { label: '启用', value: '1' },
        { label: '禁用', value: '0' },
      ],
    },
  },
];
